﻿#ifndef _CCROLE_OUTLINE_UTILS_INCLUDE
#define _CCROLE_OUTLINE_UTILS_INCLUDE


float GetCameraFOV(){
//https://answers.unity.com/questions/770838/how-can-i-extract-the-fov-information-from-the-pro.html
    float t = unity_CameraProjection._m11;
    float Rad2Deg = 180 / 3.1415;
    float fov = atan(1.0f / t) /2.0 * Rad2Deg;
    return fov;
    
}

float ApplyOutlineDistanceFadeOut(float inputMulFix){
    return saturate(inputMulFix);
}

float GetOutlineCameraFovAndDistanceFixMultiplier(float positionVS_Z){
    float cameraMulFix;
    if(unity_OrthoParams.w == 0){
    
      ////////////////////////////////
        // Perspective camera case
        ////////////////////////////////
        
        
        cameraMulFix = abs(positionVS_Z);
        cameraMulFix  = ApplyOutlineDistanceFadeOut(cameraMulFix);
        cameraMulFix *= GetCameraFOV();
       
    }
    else{
        ////////////////////////////////
        // Orthographic camera case
        ////////////////////////////////
        float orthoSize = abs(unity_OrthoParams.y);
        orthoSize = ApplyOutlineDistanceFadeOut(orthoSize);
        cameraMulFix = orthoSize * 50;// 50 is a magic number to match perspective camera's outline width
    }
    return cameraMulFix * 0.0001;

}

#endif